package socdev.mobile;

import socdev.mobile.MessageAdapter.MessageHolder;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class TasksJsonAdapter extends ArrayAdapter<Task>{
	
	Context context;
	int layoutResourceId;
	Task [] data;
	public TasksJsonAdapter(Context context, int textViewResourceId, Task [] data) {
		super(context, textViewResourceId, data);
		this.context = context;
		this.layoutResourceId = textViewResourceId;
		this.data = data;
	}

	@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        TaskHolder holder = null;
        
        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);
            
            holder = new TaskHolder();
            holder.name = (TextView)row.findViewById(R.id.name);
            holder.author = (TextView)row.findViewById(R.id.author);
            holder.text = (TextView)row.findViewById(R.id.text);
            
            row.setTag(holder);
        }
        else
        {
            holder = (TaskHolder)row.getTag();
        }
        
        Task task = data[position];
        holder.name.setText(task.name);
        holder.author.setText(task.author);
        holder.text.setText(task.text);
        return row;
    }
	
	static class TaskHolder
    {
        TextView name;
        TextView author;
        TextView text;
    }
}
